package tongcheng.com.tongcheng.ui.yemian.shenfen.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yanzhenjie.nohttp.RequestMethod;

import butterknife.Bind;
import tongcheng.com.tongcheng.ConStans;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.base.BaseActivity;
import tongcheng.com.tongcheng.bean.StatusBean;
import tongcheng.com.tongcheng.network.CallServer;
import tongcheng.com.tongcheng.network.MyRequest;
import tongcheng.com.tongcheng.network.OnCallBack;
import tongcheng.com.tongcheng.utils.GsonUtil;
import tongcheng.com.tongcheng.utils.Setting;
import tongcheng.com.tongcheng.utils.ShowToast;

public class WanShanZiLiaoActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView mBack;
    @Bind(R.id.title)
    TextView mTitle;
    @Bind(R.id.install_ll1)
    LinearLayout mInstallLl1;
    @Bind(R.id.install_ll2)
    LinearLayout mInstallLl2;
    @Bind(R.id.install_next)
    Button mInstallNext;
    @Bind(R.id.back_text)
    TextView mBackText;
    @Bind(R.id.title_bar)
    RelativeLayout mBg;

    @Bind(R.id.install_name)
    EditText mInstallName;
    @Bind(R.id.install_cardno)
    EditText mInstallCardno;
    @Bind(R.id.install_area)
    EditText mInstallArea;
    @Bind(R.id.install_phone)
    EditText mInstallPhone;


    @Override
    public Integer initResid() {
        return R.layout.activity_wan_shan_zi_liao;
    }

    @Override
    public void initCreate(Bundle savedInstanceState) {
        settitlebar(mBg);
        mTitle.setText("完善资料");
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mInstallNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String area = mInstallArea.getText().toString().trim();
                String name = mInstallName.getText().toString().trim();
                String cardno = mInstallCardno.getText().toString().trim();
                String phone = mInstallPhone.getText().toString().trim();
                if (TextUtils.isEmpty(phone)) {
                    ShowToast.showToast("手机号码不能为空");
                } else if (TextUtils.isEmpty(area)) {
                    ShowToast.showToast("城市不能为空");
                } else if (TextUtils.isEmpty(name)) {
                    ShowToast.showToast("姓名不能为空");
                }else if (TextUtils.isEmpty(cardno)) {
                    ShowToast.showToast("身份证不能为空");
                }else{
                    UpGeRenZiliao();
                }



            }
        });
    }

    //上传个人资料
    private void UpGeRenZiliao() {
        MyRequest request = new MyRequest(ConStans.UpChangInfo_Url, RequestMethod.POST);
        request.add("type", Setting.getShenfen());
        request.add("phone", Setting.getPhone());
        request.add("user_name", mInstallName.getText().toString().trim());
        request.add("address", mInstallArea.getText().toString().trim());
        request.add("idno", mInstallCardno.getText().toString().trim());
        request.add("tel", mInstallPhone.getText().toString().trim());
        CallServer.getInstance().addPost(this,request, 1, new OnCallBack() {
            @Override
            public void OnSuccess(int what, String json, Object ject) {
                Log.e("上传资料",json);
                StatusBean statusBean = GsonUtil.GsonToBean(json, StatusBean.class);
                if (statusBean != null) {
                    if (statusBean.msg != null) {
                        ShowToast.showToast(statusBean.msg);
                    }

                    if (statusBean.status == 1) {
                        //startactivity(WanShanZiLiaoActivity.this, YinHangCardActivity.class);
                        startactivity(WanShanZiLiaoActivity.this, BaoZhenJinActivity.class);
                    }
                }
            }
        });
    }


}
